package com.ocn.li.scmdy.modules.app.controller;

import com.ocn.li.scmdy.common.utils.R;
import com.ocn.li.scmdy.common.utils.RedisUtils;
import com.ocn.li.scmdy.modules.cache.DyConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @ClassName ApiDnycContrioller
 * @Description TODO
 * @Author Li9527
 * @Date 2020/9/10 13:30
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/mobile/dynaTable")
@Api(value = "ApiDynaController", tags = {"移动端--配置文件"})
public class ApiDynaController {

    @Autowired
    RedisUtils redisUtils;

    /**
     *
     * @方法：
     * @描述：下载配置文件信息，下载所有移动端需要的下拉选项和对应的选项值，如（性别：男，女）
     * @return
     */
    @GetMapping("/selectConfigureTable")
    @ApiOperation("下载配置文件信息")
    public R selectDynamicTable(@RequestParam(name = "userName", required = true) String userName) {
        System.out.println("userName-----" + userName);
        Map<Object, Object> map = redisUtils.getMap(DyConstant.RedisKey.MOBILE_EXTEND_ATTRIBUTE_JSON);
        Map<String, String> newMap = redisUtils.mapConvert(map);
        return R.ok("返回配置文件成功").put("data",newMap);
    }

    public static void main(String[] args) {
        // 栈溢出(StackOverflowError)
/*        ApiDynaContrioller oom = new ApiDynaContrioller();
        oom.stackOverFlowMethod();

        // 堆溢出(OutOfMemoryError:java heap space)
        List<byte[]> buffer = new ArrayList<byte[]>();
        buffer.add(new byte[10*1024*1024]);

        // 持久带溢出(OutOfMemoryError: PermGen space)
        List<String> list = new ArrayList<String>();
        while(true){
            list.add(UUID.randomUUID().toString().intern());
        }*/

    }

    public void stackOverFlowMethod(){
        stackOverFlowMethod();
    }



}
